//
//  HouseDetailController.m
//  PropertyMananger
//
//  Created by Mansion on 17/1/1.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "HouseDetailController.h"
#import "HouseDetailCell.h"
#import "HouseHeaderView.h"

@interface HouseDetailController ()
/*房屋信息数据源*/
@property (nonatomic,strong) NSMutableArray * infoArray;
@property (nonatomic,strong) NSArray * titleArray;
@property (nonatomic,strong) HouseHeaderView * houseHeaderView;
@end

@implementation HouseDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleViewName:@"房屋信息详情"];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initTableViewWithView:self.view frame:CGRectMake(0, 0, BHscreenW, BHscreenH) isGroup:NO];
    //表头
    self.houseHeaderView = [[HouseHeaderView alloc]initWithFrame:CGRectMake(0, 0, BHscreenW, 50)];
    self.tableView.tableHeaderView = self.houseHeaderView;
    self.houseHeaderView.titleLabel.text = @"房       屋:";
    if ([self.detailModel.LongRoomName isEqualToString:@""]) {
        
         self.houseHeaderView.infoLabel.text = @"暂无房屋信息";
    }else{
    self.houseHeaderView.infoLabel.text = [NSString stringWithFormat:@"%@",self.detailModel.LongRoomName];
    }
    
    self.tableView.backgroundColor = BHColor(238, 238, 238);
    self.tableView.showsVerticalScrollIndicator = NO;
    //注册
    [self.tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"header"];
    
    
    [self getDetailData];
}

- (void)getDetailData
{
    self.titleArray = @[@"姓       名:",@"手  机  号:",@"合同编号:",@"房屋面积:",@"房屋用途:",@"收费对象:",@"开始入住时间:",@"合同到期时间:"];
}
#pragma mark - tableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.titleArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HouseDetailCell * detailCell = [HouseDetailCell cellWithTableView:tableView];
    detailCell.titleLabel.text = self.titleArray[indexPath.row];
    
    if (indexPath.row == 0){
        
        if (![self.detailModel.OwnerName isEqualToString:@""]) {
            detailCell.infoLabel.text = self.detailModel.OwnerName;
            
        }
        
    }else if (indexPath.row == 1){
        
        if (self.detailModel.LinkTel != nil) {
            
            [detailCell.phoneBtn setImage:IMG(@"ico_dial_telephone") forState:UIControlStateNormal];
            [detailCell.phoneBtn addTarget:self action:@selector(phoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            detailCell.infoLabel.text = self.detailModel.LinkTel;
        }else{
            
         detailCell.infoLabel.text = @"";
         detailCell.phoneBtn.hidden = YES;
            
        }

    
    }else if (indexPath.row == 2){
        
        if (self.detailModel.ContractNo != nil) {
            detailCell.infoLabel.text = self.detailModel.ContractNo;
        }else{
            detailCell.infoLabel.text = @"";
        }
        
    } else if (indexPath.row == 3){
        
        if (self.detailModel.ChargingArea != nil) {
            detailCell.infoLabel.text = [NSString stringWithFormat:@"%@㎡",self.detailModel.ChargingArea];
        }else{
            detailCell.infoLabel.text = @"";
        }
        
        
    }else if (indexPath.row == 4){
        
        if (self.detailModel.RoomUse != nil) {
            detailCell.infoLabel.text = self.detailModel.RoomUse;
        }else{
            detailCell.infoLabel.text = @"";
        }

        
    }else if (indexPath.row == 5){
        if (self.detailModel.OwnerName != nil) {
            detailCell.infoLabel.text = self.detailModel.OwnerName;
        }else{
            detailCell.infoLabel.text = @"";
        }

        
    }else if (indexPath.row == 6){
        if (self.detailModel.CheckInDate != nil) {
            detailCell.infoLabel.text = self.detailModel.CheckInDate;
        }else{
            detailCell.infoLabel.text = @"";
        }

        
    }else if (indexPath.row == 7){
        
        if (self.detailModel.ContractEndDate != nil) {
            detailCell.infoLabel.text = self.detailModel.ContractEndDate;
        }else{
            detailCell.infoLabel.text = @"";
        }

    }
    return detailCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    UITableViewHeaderFooterView * headerView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"header"];
    headerView.detailTextLabel.text = @"房屋:";
    return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
#pragma mark - 打电话点击事件
- (void)phoneBtnClick:(UIButton *)button{

    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",self.detailModel.LinkTel];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
    DLog(@"拨打电话");

}
@end
